package com.kiln.juxingqs.dialog

import androidx.databinding.ObservableField
import androidx.fragment.app.FragmentActivity
import com.kiln.juxingqs.R
import com.kiln.juxingqs.databinding.DialogSelectskuBinding
import com.tzstore.oo.dialog.BottomBindingDialog

class SelectSkuDialog(context: FragmentActivity) :
    BottomBindingDialog<DialogSelectskuBinding>(context) {
    val activity: FragmentActivity

    lateinit var id: String
    lateinit var price: String
    lateinit var imgUrl: String
    lateinit var name: String

    val selectNum = ObservableField<String>("1")

    init {
        activity = context
    }

    override fun getV(): Int {
        return R.layout.dialog_selectsku
    }

    override fun postBinding() {
        binding.event = this
        window?.setWindowAnimations(R.style.dialogWindowAnimButtomToTop);
        window?.setBackgroundDrawableResource(android.R.color.transparent)
    }

    fun changeNum(n: Int) {
        var num = 0
        try {
            num = selectNum.get()!!.toInt()
            num = num + n
            if (num < 1)
                num = 1
            selectNum.set("$num")
        } catch (e: Exception) {
        }
    }

    var ok: ((uri: String) -> Unit)? = null

    fun queren() {
        cancel()
        ok?.invoke(selectNum.get() as String)
    }
}